# 循环数组,定义一个变量x 遇到一个奇数 x+1 下一个数如果不是奇数x清零 否则+1 x到3停止
# x = 0
# arr = [1, 3, 5, 8, 9, 10]
# for i in range(len(arr)):  # arr[i]
#     # print('x--->', x)
#     if x == 3:
#         print(True)
#         break
#     else:
#         if arr[i] % 2 != 0:
#             x += 1
#             # print(f'{arr[i]} is odd')
#         else:
#             # print(f'{arr[i]} is even')
#             x = 0
# if x < 3:
#     print(False)

# 循环数组,定义一个变量x 遇到一个奇数 x+1 下一个数如果不是奇数x清零 否则+1 x到3停止
# x = 0
# arr = [1, 2, 34, 3, 4, 5, 4, 7, 23, 12]
# for i in range(len(arr)):  # arr[i]
#     if arr[i] % 2 != 0:
#         x += 1
#         print(arr[i], x)
#     else:
#         x = 0
# if x <= 3:
#     print(True)
# else:
#     print(False)

# d = {12: 100, 3: 9, 8: 300.1}
# num_cls = int, float
# keys = [i for i in d if type(i) in num_cls]  # 可相加的键  [8]
# values = [i for i in d.values() if type(i) in num_cls]  # 可相加的值 [100, 300.1]
# nums = sum(keys + values)
# print(nums)
# d = {'a': 100, (): '9', 8: 300.1}
# keys = []
# for i in d:
#     if type(i) in (int, float):
#         print(i)
#         keys.append(i)
# print(keys)
#
# for i in d.values():
#     if type(i) in (int, float):
#         print(i)
#         keys.append(i)
# print(keys)
# # print(sum(keys))
# FileName = ["10.py", "2.py", "8.py", "6.py", "100.py"]
# keys = [i[:-3] for i in FileName]
# keys.sort(key=int)
# nwe_fileName = [i + '.py' for i in keys]
# print(nwe_fileName)

"""
请定义一个求 「动态和」 的函数:
传入一个数组 nums 。数组 「动态和」 的计算公式为: runningSum[i] = sum(nums[0]…nums[i]) 。

函数返回 nums 的动态和。

示例 1:
输入: nums = [1, 2, 3, 4]
输出: [1, 3, 6, 10]
解释: 动态和计算过程为 [1, 1+2, 1+2+3, 1+2+3+4] 。
"""


# nums = [1, 2, 3, 4]
# arr = []
# x = 0
# for i in nums:
#     x = i + x
#     arr.append(x)
#     print(x)
# print(arr)


# FileName.sort(kef=)
# 自定义排序函数，提取文件名中的数字并转换为整数
# def extract_number(filename):
#     return int(filename[:-3])
#
#
# # 按照数字从小到大的顺序排序
# sorted_files = sorted(FileName, key=extract_number)
#
# # 打印排序后的列表
# print(sorted_files)

# 已知 FileName = ["10.py", "2.py", "8.py", "6.py", "100.py"]
# 已知 FileName = ["10.py", "2.py", "8.py", "6.py", "100.py"], 请对文件名按照数字从小到大排序

# def sort_files_by_number(files):
#     # 提取文件名中的数字
#     numbers = [int(file[:-3]) for file in files]
#     # 按照数字排序
#     sorted_numbers = sorted(numbers)
#     # 按照数字排序后的文件名列表
#     sorted_files = [file for file in files if file[:-3] in str(sorted_numbers)]
#     return sorted_files


# 测试
# FileName = ["10.py", "2.py", "8.py", "6.py", "100.py"]
# sorted_files = sort_files_by_number(FileName)
# print(sorted_files)

class Student:
    def __init__(self, name, age, score):
        self.name = name
        self.age = age
        self.score = score

    def get_info(self):
        return f"Name: {self.name}, Age: {self.age}, Score: {self.score}"


class ClassRoom:
    def __init__(self, name):
        self.name = name
        self.students = []

    def add_student(self, student):
        if student not in self.students:
            self.students.append(student)
            print(f"Student {student.name} added to {self.name}")

    def remove_student(self, student):
        if student in self.students:
            self.students.remove(student)
            print(f"Student {student.name} removed from {self.name}")
        else:
            print(f"Student {student.name} not found in {self.name}")

    def get_students_info(self):
        print(f"Class: {self.name}")
        for student in self.students:
            print(student.get_info())


# 测试代码
if __name__ == "__main__":
    # 创建学生对象
    student1 = Student("Alice", 18, 90)
    student2 = Student("Bob", 17, 85)
    student3 = Student("Charlie", 19, 92)

    # 创建班级对象
    class_room = ClassRoom("Class A")

    # 添加学生到班级
    class_room.add_student(student1)
    class_room.add_student(student2)

    # 打印班级学生信息
    class_room.get_students_info()
    print(1)
    # 移除学生
    class_room.remove_student(student3)  # 学生不存在
    class_room.remove_student(student1)

    # 打印更新后的班级学生信息
    class_room.get_students_info()
